package com.sky.controller.employee;

import com.sky.constant.MonitorStatusConstant;
import com.sky.dto.MeetingRoomMonitorPageQueryDTO;
import com.sky.dto.MonitorDTO;
import com.sky.entity.Monitor;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.MonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee/monitor")
@Slf4j
@CrossOrigin
@Builder
@Api(tags = "会议室监控")
public class MonitorController {
    @Autowired
    private MonitorService monitorService;

    // 会议室状态查看
    @ApiOperation(value="分页查询会议室监控信息")
    @GetMapping("/page")
    public Result<PageResult> page(MeetingRoomMonitorPageQueryDTO meetingRoomMonitorPageQueryDTO){
        log.info("分页查询: {}", meetingRoomMonitorPageQueryDTO); //框架会自动将数据封装到实体类对象中，即使有一些为空
        PageResult pageResult = monitorService.pageQuery(meetingRoomMonitorPageQueryDTO);
        return Result.success(pageResult);
    }

    // 根据id调用会议室监控
    @ApiOperation(value="根据id调用会议室监控")
    @PostMapping("/call/{id}")
    public Result<String> call(@PathVariable Long id, MonitorDTO monitorDTO){
        log.info("根据id调用会议室监控: {} , {}", id, monitorDTO);
        if (monitorService.callMeetingRoomMonitor(id, monitorDTO)) {
            return Result.success(MonitorStatusConstant.callSuccess);
        } else {
            return Result.error(MonitorStatusConstant.callError);
        }
    }

    // 根据id回显会议室监控信息
    @ApiOperation(value="根据id回显会议室监控信息")
    @GetMapping("/{id}")
    public Result<List<Monitor>> getDetailById(@PathVariable Long id){
        log.info("根据id回显会议室监控信息: {}", id);
        List<Monitor> monitorList = monitorService.getMonitorDetailById(id);
        return Result.success(monitorList);
    }

}
